﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
using VOL.Domain.IServices.ProductionManagement;
using VOL.Entity.DomainModels;

namespace VOL.WebApi.Controllers.ProductionManagement
{
    /// <summary>
    /// 生产工单
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class WorkOrderController : ControllerBase
    {
        private IWorkOrderService _workOrderService;

        public WorkOrderController(IWorkOrderService workOrderService)
        {
            _workOrderService = workOrderService;
        }

        /// <summary>
        /// 生产工单新增
        /// </summary>
        /// <param name="workOrder"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> AddWorkOrder([FromBody]WorkOrder workOrder)
        {
            return await _workOrderService.AddWorkOrder(workOrder);
        }
        /// <summary>
        /// 生产工单删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<int> DeleteWorkOrder(int id)
        {
            return await _workOrderService.DeleteWorkOrder(id);
        }
        /// <summary>
        /// 生产工单显示
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<WorkOrder>> GetAllWorkOrder(int pageIndex = 1, int pageSize = 5)
        {
            return await _workOrderService.GetAllWorkOrder(pageIndex, pageSize);
        }
        /// <summary>
        /// 生产工单修改
        /// </summary>
        /// <param name="workOrder"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> UpdateWorkOrder([FromBody]WorkOrder workOrder)
        {
            return await _workOrderService.UpdateWorkOrder(workOrder);
        }
    }
}
